using System;
using System.Linq;
using System.Web.Mvc;
using C3.Directory.Services;
using CSI.Directory.Core.Services;
using StructureMap;

namespace CSI.Directory.Web.Controllers
{
    public class FileUploadJsonResult : JsonResult
    {
        public override void ExecuteResult(ControllerContext context)
        {
            ContentType = "text/html";
            context.HttpContext.Response.Write("<textarea>");
            base.ExecuteResult(context);
            context.HttpContext.Response.Write("</textarea>");
        }
    }

    public abstract class BaseController: Controller
    {
        
        public IUserService UserService { get { return ObjectFactory.GetInstance<IUserService>(); } }
        public ISessionService SessionService { get { return ObjectFactory.GetInstance<ISessionService>(); } }
        public IDirectoryService DirectoryService{ get { return ObjectFactory.GetInstance<IDirectoryService>(); }}
        public ITransactionService TransactionService { get { return ObjectFactory.GetInstance<ITransactionService>(); } }

        protected override void Execute(System.Web.Routing.RequestContext requestContext)
        {
            try
            {
                ViewData["User"] =null;

                if (SessionService.CurrentUser != null)
                {
                    ViewData["User"] = SessionService.CurrentUser;
                }
                ViewData["Categories"] = DirectoryService.GetAllCategories().OrderBy(t => t.Name).ToList();
                ViewData["Counties"] = DirectoryService.GetAllCounties().OrderBy(t => t.Name).ToList();
            }
            catch
            {
              
            }
            base.Execute(requestContext);


        }
        protected new JsonResult Json(Object data)
        {
            return Json(data, JsonRequestBehavior.AllowGet);
        }

    }
}